package weather.util.dictionary;

import java.io.*;

import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;

/**
 * @author Jerzy Mazurek WEiTI PW
 */
public abstract class AbstractDictionary
{
	public abstract void loadFromXlsFile(File path, int sheetNumber) throws IOException;
	
	protected Workbook openWorkbook(File path) throws IOException
	{
		InputStream in = null;
		Workbook wb = null;
		
		try
		{
			in = new BufferedInputStream(new FileInputStream(path));
			wb = new HSSFWorkbook(in);
			
			closeInputStream(in);
			
			return wb;
		}
		catch (FileNotFoundException e)
		{
			e.printStackTrace();
			throw e;
		}
		catch (IOException e)
		{
			e.printStackTrace();
			closeInputStream(in);
			throw e;
		}
	}
	
	private void closeInputStream(InputStream in)
	{
		try
		{
			in.close();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
}
